package com.coda.controller;

import com.coda.adminVo.agreement.AgreementQueryVo;
import com.coda.adminVo.agreement.AgreementVo;
import com.coda.entity.LeaseAgreement;
import com.coda.result.PageResult;
import com.coda.result.Result;
import com.coda.service.LeaseAgreementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController()
@RequestMapping("/admin/agreement")
@Api(tags = "租约管理")
public class LeaseAgreementController {
    @Autowired
    private LeaseAgreementService leaseAgreementService;
    /**
     * 根据条件分页查询租约列表
     */
    @GetMapping("/page")
    @ApiOperation("根据条件分页查询租约列表")
    public Result<PageResult> getPageList(@RequestParam Integer current,
                                          @RequestParam Integer size,
                                          AgreementQueryVo queryVo){
        PageResult pageResult = leaseAgreementService.getPageList(current,size,queryVo);
        return Result.ok(pageResult);

    }
    /**
     * 根据id查询租约信息
     */
    @GetMapping(name = "getById")
    @ApiOperation("根据id查询租约信息")
    public Result<AgreementVo> getById(@RequestParam Long id){
        AgreementVo agreementVo = leaseAgreementService.getById(id);
        return Result.ok(agreementVo);
    }
    /**
     * 保存或更新租约信息
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存或更新租约信息")
    public Result saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement){
        leaseAgreementService.saveOrUpdate(leaseAgreement);
        return Result.ok();
    }
    /**
     * 根据id删除租约信息
     */
    @DeleteMapping("/removeById")
    @ApiOperation("根据id删除租约信息")
    public Result removeById(Long id){
        leaseAgreementService.deleteById(id);
        return Result.ok();
    }

    /**
     * 根据ID更新租约状态
     */
    @PostMapping("/updateStatusById")
    @ApiOperation("根据ID更新租约状态")
    public Result updateStatusById(Long id,Integer status){
        leaseAgreementService.updateStatusById(id,status);
        return Result.ok();
    }
}
